package com.hx.entity;
import com.hx.service.CallService;
import com.hx.service.SendService;
import java.io.Serializable;
import java.util.*;
public class TalkPackage extends ServicePackage implements CallService, SendService , Serializable {
    public int talkTime;
    public int smsCount;
    public double price;
    public int getTalkTime() {
        return talkTime;
    }
    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }
    public int getSmsCount() {
        return smsCount;
    }
    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

   public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }

    public TalkPackage() {
       super(58,"话唠套餐");
        this.talkTime = 500;
        this.smsCount = 30;
        this.price = 58;
    }
    public void showInfo() {
        System.out.println( "话唠套餐：通话时长为：" + this.getTalkTime() + "分钟/月,短信条数为："
                + this.getSmsCount() + "条/月,资费为："
                + this.getPrice() + "元/月" );
    }
    public int  call(int MinCount, MobileCard card) {
        int temp = MinCount;
        for (int i = 0; i < MinCount; i++) {
            if (this.talkTime - card.getRealTalkTime() >= 1) {
                card.setRealTalkTime( card.getRealTalkTime() + 1 );  //实际通话数据加1
            } else if (card.getMonery() >= 0.2) {
                card.setRealTalkTime( card.getRealTalkTime() + 1 ); // 实际通话时长1分钟
                //账户余额消费0.2元（1分钟 额外通话）
                card.setMonery( card.getMonery()+ 0.2  );
                card.setConsumAmont( card.getConsumAmont() + 0.2 );
            } else {
                temp = i;
                try {
                    throw new Exception( "本次通话" + i + "分钟，您的余额不足，请充值后再使用！" );
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
       } return temp;
    }
    public int send(int count, MobileCard card) {
        int temp = count;
        for (int i = 0; i < count; i++) {
            if (this.smsCount - card.getRealSMSCount() >= 1) {
                card.setRealSMSCount( card.getRealSMSCount() + 1 );
            } else if (card.getMonery() >= 0.1) {
                card.setRealSMSCount( card.getRealSMSCount() + 1 ); //实际短信数加 1 条
                //账户余额消费0.1元，（一条短信）
                card.setMonery( card.getMonery() - 0.1 );
                card.setConsumAmont( card.getConsumAmont() + 0.1 );  //当月消费金额 + 0.1
            } else {
                temp = i; //记录发短信条数
                try {
                    throw new Exception( "短信已经发送" + i + "条，您的余额不足，请充值后再使用！" );
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return temp;
    }
}